﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;

namespace WMI.NET.CIM
{
    /// <summary>
    /// A CIM_Action class is an operation that is part of a process to either create a software element in its next state or to eliminate the software element in the current state. 
    /// </summary>
    public class CIM_Action
    {

        private string _ActionID;
        private string _Caption;
        private string _Description;
        private Nullable<UInt16> _Direction;
        private string _Name;
        private string _SoftwareElementID;
        private Nullable<UInt16> _SoftwareElementState;
        private Nullable<UInt16> _TargetOperatingSystem;
        private string _Version;

        /// <summary>
        /// Unique identifier assigned to a particular action for a software element.
        /// </summary>
        public string ActionID { get { return _ActionID; } }

        /// <summary>
        /// Short textual description of the object. 
        /// </summary>
        public string Caption { get { return _Caption; } }

        /// <summary>
        /// Description of the object.
        /// </summary>
        public string Description { get { return _Description; } }

        /// <summary>
        /// Indicates whether a particular CIM_Action object is part of a sequence of actions to transition the current software element to its next state, such as "Install", or to remove the current software element, such as "Uninstall".
        /// </summary>
        public Nullable<UInt16> Direction { get { return _Direction; } } //TODO enum

        /// <summary>
        /// Identifies the software element.
        /// </summary>
        public string Name { get { return _Name; } }

        /// <summary>
        /// Identifier for the software element.
        /// </summary>
        public string SoftwareElementID { get { return _SoftwareElementID; } }

        /// <summary>
        /// State of a software element.
        /// </summary>
        public Nullable<UInt16> SoftwareElementState { get { return _SoftwareElementState; } } //TODO enum

        /// <summary>
        /// Target operating system of the owning software element.
        /// </summary>
        public Nullable<UInt16> TargetOperatingSystem { get { return _TargetOperatingSystem; } } //TODO enum

        /// <summary>
        /// Version of the operation.
        /// The version of the operation should be in one of the following forms:
        ///    major.minor.revision
        /// </summary>
        public string Version { get { return _Version; } }


        /// <summary>
        /// The Invoke method of the CIM_Action class takes a particular action. The details of how the method performs the action is implementation-specific.
        /// </summary>
        /// <returns></returns>
        public UInt32 Invoke() { throw new NotImplementedException(); }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="mbo"></param>
        public CIM_Action(ManagementBaseObject mbo)
        {
            _ActionID = mbo.GetStringValue("ActionID");
            _Caption = mbo.GetStringValue("Caption");
            _Description = mbo.GetStringValue("Description");
            _Direction = mbo.GetUshortValue("Direction");
            _Name = mbo.GetStringValue("Name");
            _SoftwareElementID = mbo.GetStringValue("SoftwareElementID");
            _SoftwareElementState = mbo.GetUshortValue("SoftwareElementState");
            _TargetOperatingSystem = mbo.GetUshortValue("TargetOperatingSystem");
            _Version = mbo.GetStringValue("Version");
        }
    }
}
